package model.item;

import model.entity.BasicEntity;
import model.skill.Projectile;
import utilities.*;

abstract public class ProjectileItem extends Item implements Archiveable {

	private Projectile projectile;
	
	public ProjectileItem() {
		this(null);
	}
	
	public ProjectileItem(String name)
	{
		super(name);
		projectile = null;
	}
	
	public ProjectileItem(String name, Projectile projectile)
	{
		super(name);
		this.projectile = projectile;
	}
	
	public Projectile getProjectile()
	{
		return projectile;
	}
	
	abstract public void touch(BasicEntity entity);
	
	
	public Archive save() {
		Archive archive = super.save();
		
		archive.putClassName("projectile", this.projectile.getClass().getName());
		archive.putOneRelationship("projectile", this.projectile);
		
		return archive;
	}
	
	public void load(Archive archive) {
		super.load(archive);
		
		this.projectile = (Projectile)ModelFactory.getInstance().createInstanceWithClassName(archive.getClassName("projectile"));
		this.projectile.load(archive.getOneRelationship("projectile"));
	}
}